import java.util.zip.CRC32;
import java.util.zip.Checksum;
import java.util.*;

public class SubStringWithConcatenation {
	public List<Integer> findSubstring(String S, String[] L) {
        int n = L[0].length();
        
        List <Integer> result = new ArrayList <Integer> ();
        
        ArrayList <Long> lhash = new ArrayList <Long> ();
        
        for(int i = 0 ; i < L.length ; i++) {
            lhash.add(hash(L[i]));
//             System.out.println(hash(L[i])+" "+L[i]);
        }
        
        Collections.sort(lhash);

        for(int i = 0 ; i < S.length()+1-L.length*n ; i++) {
            
            ArrayList <Long> lhashCopy = new ArrayList <Long> ();
            lhashCopy = (ArrayList<Long>) lhash.clone();
            
            int k = 0;
            for(k = i ; k < S.length() && k >= 0 ; k = k+n) {
                
                for(int j = 0 ; j < L.length ;) {
        	        int position = bs(lhashCopy, 0, hash(S.substring(k,k+n)));
        	        
        	        // System.out.println(lhashCopy.size()+" "+position +" "+hash(S.substring(k,k+n))+" "+ S.substring(k,k+n));
        	        
        	        if(position == -1) {
        	            k = -100;
        	            break;
        	        }
        	        else {
        	            lhashCopy.remove(position);
        	            
        	            if(lhashCopy.size() == 0) {
                    		result.add(i);
                    		k = -100;
                    		break;
                    	}
        	            
        	            break;
        	        }
                }
            }
        }
        
        return result;
    }
    
    // public int bs(long[] a, int s, long t) {
    //     int lo = s;
    //     int hi = a.length - 1;
    //     while (lo <= hi) {
    //         int mid = lo + (hi - lo) / 2;
    //         if (t < a[mid]) hi = mid - 1;
    //         else if (t > a[mid]) lo = mid + 1;
    //         else return mid;
    //     }
    //     return -1;
    // }
    
    public long hash(String in) {
        long result = 0;
        for(int i = 0 ; i < in.length() ; i++) {
            result = result * 26 + in.charAt(i);
        }
        return result;
    }
    
    public int bs(ArrayList <Long> a, int s, long t) {
        int lo = s;
        int hi = a.size() - 1;
        while (lo <= hi) {
            int mid = lo + (hi - lo) / 2;
            if (t < a.get(mid)) hi = mid - 1;
            else if (t > a.get(mid)) lo = mid + 1;
            else return mid;
        }
        return -1;
    }
}